package com.skstudio.nuprint.lpd;

import java.io.Reader;
import java.io.Writer;
import java.util.List;


public class CommandReportQueueStateShort extends CommandHandler {

	public CommandReportQueueStateShort(Reader in, Writer out) {
		super(in, out);
	}
	
	@Override
	public void execute(byte[] command) throws Exception {
		String[] opds = CommandHandler.parseOperands(command);
		String queueName = opds[0];
		String options = opds[1];
		
		StringBuilder sb = new StringBuilder();
		sb.append(CommandHandler.createFixedLengthString("Job Id", LpdPrintJob.JOB_ID_LENGTH));
		sb.append(CommandHandler.createFixedLengthString("Name", LpdPrintJob.JOB_NAME_LENGTH));
		sb.append(CommandHandler.createFixedLengthString("Owner", LpdPrintJob.JOB_OWNER_LENGTH));
		sb.append("\n");
		
		List<LpdPrintJob> list = LpdQueue.getInstance().getPrintJobs(queueName, options);
		for (LpdPrintJob job : list) {
			sb.append(job.getShortDescription());
			sb.append("\n");
		}
		
		mWriter.write(sb.toString());
		mWriter.flush();
	}
}
